package com.cjxt.ams.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cjxt.ams.dao.UserRoleDao;
import com.cjxt.ams.domain.UserRole;
import com.cjxt.ams.service.UserRoleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description: 用户与角色对应关系
 * @author JK_a
 * @date 2021/11/22 20:04
 * @param
 */

@Service("userRoleService")
public class UserRoleServiceImpl extends ServiceImpl<UserRoleDao, UserRole> implements UserRoleService{


    @Override
    public void saveOrUpdate(Integer userId, Integer roleId) {

        /**
         * 删除用户与角色关系
         */
        this.remove(new QueryWrapper<UserRole>().eq("user_id",userId));

        if (roleId == null){
            return;
        }

        /**
         * 保存用户与角色关系
         */

            UserRole userRole = new UserRole();
            userRole.setUserId(userId);
            userRole.setRoleId(roleId);

            this.save(userRole);

    }

    @Override
    public List<Integer> queryRoleIdList(Integer userId) {
        return baseMapper.queryRoleIdList(userId);
    }

    @Override
    public Integer deleteBatch(Integer[] roleIds) {
        return baseMapper.deleteBatch(roleIds);
    }
}
